/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.swt.mto.thithu.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.swt.mto.thithu.model.Answer;
import com.swt.mto.thithu.model.AnswerModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * The base model implementation for the Answer service. Represents a row in the &quot;mto_thithu_Answer&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.swt.mto.thithu.model.AnswerModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AnswerImpl}.
 * </p>
 *
 * @author tuan.nguyen
 * @see AnswerImpl
 * @see com.swt.mto.thithu.model.Answer
 * @see com.swt.mto.thithu.model.AnswerModel
 * @generated
 */
public class AnswerModelImpl extends BaseModelImpl<Answer>
	implements AnswerModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a answer model instance should use the {@link com.swt.mto.thithu.model.Answer} interface instead.
	 */
	public static final String TABLE_NAME = "mto_thithu_Answer";
	public static final Object[][] TABLE_COLUMNS = {
			{ "answerId", Types.BIGINT },
			{ "questionId", Types.BIGINT },
			{ "createUserId", Types.BIGINT },
			{ "modifyUserId", Types.BIGINT },
			{ "decription", Types.VARCHAR },
			{ "answerType", Types.INTEGER },
			{ "correct", Types.VARCHAR },
			{ "answerPosition", Types.INTEGER },
			{ "createDate", Types.TIMESTAMP },
			{ "modifydate", Types.TIMESTAMP }
		};
	public static final String TABLE_SQL_CREATE = "create table mto_thithu_Answer (answerId LONG not null primary key,questionId LONG,createUserId LONG,modifyUserId LONG,decription VARCHAR(75) null,answerType INTEGER,correct VARCHAR(75) null,answerPosition INTEGER,createDate DATE null,modifydate DATE null)";
	public static final String TABLE_SQL_DROP = "drop table mto_thithu_Answer";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.swt.mto.thithu.model.Answer"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.swt.mto.thithu.model.Answer"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.swt.mto.thithu.model.Answer"));

	public AnswerModelImpl() {
	}

	public long getPrimaryKey() {
		return _answerId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAnswerId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_answerId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Answer.class;
	}

	public String getModelClassName() {
		return Answer.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("answerId", getAnswerId());
		attributes.put("questionId", getQuestionId());
		attributes.put("createUserId", getCreateUserId());
		attributes.put("modifyUserId", getModifyUserId());
		attributes.put("decription", getDecription());
		attributes.put("answerType", getAnswerType());
		attributes.put("correct", getCorrect());
		attributes.put("answerPosition", getAnswerPosition());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifydate", getModifydate());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long answerId = (Long)attributes.get("answerId");

		if (answerId != null) {
			setAnswerId(answerId);
		}

		Long questionId = (Long)attributes.get("questionId");

		if (questionId != null) {
			setQuestionId(questionId);
		}

		Long createUserId = (Long)attributes.get("createUserId");

		if (createUserId != null) {
			setCreateUserId(createUserId);
		}

		Long modifyUserId = (Long)attributes.get("modifyUserId");

		if (modifyUserId != null) {
			setModifyUserId(modifyUserId);
		}

		String decription = (String)attributes.get("decription");

		if (decription != null) {
			setDecription(decription);
		}

		Integer answerType = (Integer)attributes.get("answerType");

		if (answerType != null) {
			setAnswerType(answerType);
		}

		String correct = (String)attributes.get("correct");

		if (correct != null) {
			setCorrect(correct);
		}

		Integer answerPosition = (Integer)attributes.get("answerPosition");

		if (answerPosition != null) {
			setAnswerPosition(answerPosition);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifydate = (Date)attributes.get("modifydate");

		if (modifydate != null) {
			setModifydate(modifydate);
		}
	}

	public long getAnswerId() {
		return _answerId;
	}

	public void setAnswerId(long answerId) {
		_answerId = answerId;
	}

	public long getQuestionId() {
		return _questionId;
	}

	public void setQuestionId(long questionId) {
		_questionId = questionId;
	}

	public long getCreateUserId() {
		return _createUserId;
	}

	public void setCreateUserId(long createUserId) {
		_createUserId = createUserId;
	}

	public String getCreateUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getCreateUserId(), "uuid",
			_createUserUuid);
	}

	public void setCreateUserUuid(String createUserUuid) {
		_createUserUuid = createUserUuid;
	}

	public long getModifyUserId() {
		return _modifyUserId;
	}

	public void setModifyUserId(long modifyUserId) {
		_modifyUserId = modifyUserId;
	}

	public String getModifyUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getModifyUserId(), "uuid",
			_modifyUserUuid);
	}

	public void setModifyUserUuid(String modifyUserUuid) {
		_modifyUserUuid = modifyUserUuid;
	}

	public String getDecription() {
		if (_decription == null) {
			return StringPool.BLANK;
		}
		else {
			return _decription;
		}
	}

	public void setDecription(String decription) {
		_decription = decription;
	}

	public int getAnswerType() {
		return _answerType;
	}

	public void setAnswerType(int answerType) {
		_answerType = answerType;
	}

	public String getCorrect() {
		if (_correct == null) {
			return StringPool.BLANK;
		}
		else {
			return _correct;
		}
	}

	public void setCorrect(String correct) {
		_correct = correct;
	}

	public int getAnswerPosition() {
		return _answerPosition;
	}

	public void setAnswerPosition(int answerPosition) {
		_answerPosition = answerPosition;
	}

	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	public Date getModifydate() {
		return _modifydate;
	}

	public void setModifydate(Date modifydate) {
		_modifydate = modifydate;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Answer.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Answer toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Answer)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		AnswerImpl answerImpl = new AnswerImpl();

		answerImpl.setAnswerId(getAnswerId());
		answerImpl.setQuestionId(getQuestionId());
		answerImpl.setCreateUserId(getCreateUserId());
		answerImpl.setModifyUserId(getModifyUserId());
		answerImpl.setDecription(getDecription());
		answerImpl.setAnswerType(getAnswerType());
		answerImpl.setCorrect(getCorrect());
		answerImpl.setAnswerPosition(getAnswerPosition());
		answerImpl.setCreateDate(getCreateDate());
		answerImpl.setModifydate(getModifydate());

		answerImpl.resetOriginalValues();

		return answerImpl;
	}

	public int compareTo(Answer answer) {
		long primaryKey = answer.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Answer answer = null;

		try {
			answer = (Answer)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = answer.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<Answer> toCacheModel() {
		AnswerCacheModel answerCacheModel = new AnswerCacheModel();

		answerCacheModel.answerId = getAnswerId();

		answerCacheModel.questionId = getQuestionId();

		answerCacheModel.createUserId = getCreateUserId();

		answerCacheModel.modifyUserId = getModifyUserId();

		answerCacheModel.decription = getDecription();

		String decription = answerCacheModel.decription;

		if ((decription != null) && (decription.length() == 0)) {
			answerCacheModel.decription = null;
		}

		answerCacheModel.answerType = getAnswerType();

		answerCacheModel.correct = getCorrect();

		String correct = answerCacheModel.correct;

		if ((correct != null) && (correct.length() == 0)) {
			answerCacheModel.correct = null;
		}

		answerCacheModel.answerPosition = getAnswerPosition();

		Date createDate = getCreateDate();

		if (createDate != null) {
			answerCacheModel.createDate = createDate.getTime();
		}
		else {
			answerCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifydate = getModifydate();

		if (modifydate != null) {
			answerCacheModel.modifydate = modifydate.getTime();
		}
		else {
			answerCacheModel.modifydate = Long.MIN_VALUE;
		}

		return answerCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(21);

		sb.append("{answerId=");
		sb.append(getAnswerId());
		sb.append(", questionId=");
		sb.append(getQuestionId());
		sb.append(", createUserId=");
		sb.append(getCreateUserId());
		sb.append(", modifyUserId=");
		sb.append(getModifyUserId());
		sb.append(", decription=");
		sb.append(getDecription());
		sb.append(", answerType=");
		sb.append(getAnswerType());
		sb.append(", correct=");
		sb.append(getCorrect());
		sb.append(", answerPosition=");
		sb.append(getAnswerPosition());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifydate=");
		sb.append(getModifydate());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(34);

		sb.append("<model><model-name>");
		sb.append("com.swt.mto.thithu.model.Answer");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>answerId</column-name><column-value><![CDATA[");
		sb.append(getAnswerId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>questionId</column-name><column-value><![CDATA[");
		sb.append(getQuestionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createUserId</column-name><column-value><![CDATA[");
		sb.append(getCreateUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifyUserId</column-name><column-value><![CDATA[");
		sb.append(getModifyUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>decription</column-name><column-value><![CDATA[");
		sb.append(getDecription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>answerType</column-name><column-value><![CDATA[");
		sb.append(getAnswerType());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>correct</column-name><column-value><![CDATA[");
		sb.append(getCorrect());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>answerPosition</column-name><column-value><![CDATA[");
		sb.append(getAnswerPosition());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifydate</column-name><column-value><![CDATA[");
		sb.append(getModifydate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Answer.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Answer.class
		};
	private long _answerId;
	private long _questionId;
	private long _createUserId;
	private String _createUserUuid;
	private long _modifyUserId;
	private String _modifyUserUuid;
	private String _decription;
	private int _answerType;
	private String _correct;
	private int _answerPosition;
	private Date _createDate;
	private Date _modifydate;
	private Answer _escapedModelProxy;
}